home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_exmh.idb / usr / freeware / lib / exmh-2.5 / print.tcl.z / print.tcl
Text File  |  2002-07-08  |  5KB  |  185 lines

  1. # Print
  2. #
  3.  
  4. proc Print_Init {} {
  5.     Preferences_Add "Printing" \
  6. "Use these items to control how Exmh prints mail messages.  In the print command, the variable \$file is replaced by the name of the file(s) so you can embed it into a pipeline.  See Frequently Asked Question #17 for tips about
  7. alternate print commands that do formatting." {
  8.     {print(cmd) printCmd {lpr $file} {Text print command}
  9. "This command is used to print the current message.
  10. The variable $file is replaced by the name of the file(s)
  11. so you can embed it into a pipeline."} \
  12.     {print(pscmd) psPrintCmd {lpr $file} {Postscript print command}
  13. "This command is used to print postscript from the current message.
  14. The variable $file is replaced by the name of the tmp file
  15. that contains the postscript."} \
  16.     {print(unixcmd) unixCmd {cat $file > /dev/null} {Arbitrary UNIX command}
  17. "This command is used to run a UNIX command over the body of the message.
  18. \$file is replaced with the name of the temporary file."} \
  19.     }
  20. }
  21. proc Print {} {
  22.     global exmh msg print mhProfile address
  23.     set logvar {}
  24.     set file {}
  25.     Ftoc_Iterate line {
  26.     set msgid [Ftoc_MsgNumber $line]
  27.     lappend file $mhProfile(path)/$exmh(folder)/$msgid
  28.     }
  29.     set nprint [llength $file]
  30.     if {$nprint == 0} {
  31.     Exmh_Status "No messages selected for printing" red
  32.     return
  33.     }
  34.     set plural s
  35.     if {$nprint == 1} {
  36.     set plural ""
  37.     }
  38.     Exmh_Status "Printing $nprint message$plural"
  39.  
  40.     # Because $print(cmd) embeds $file, extra levels of eval are required
  41.     if {[catch {eval eval exec $print(cmd)} logvar]} {
  42.     if [Exwin_Toplevel .printmsg "Print Messages"] {
  43.         Widget_Message .printmsg msg -aspect 1500 -relief raised 
  44.     }
  45.     .printmsg.msg configure -text \
  46. "Messages generated when printing your message$plural:
  47.  
  48. $logvar
  49. "
  50.  
  51.     }
  52. }
  53.  
  54. proc Print_Postscript {} {
  55.     global exmh msg mhProfile print
  56.     if [catch {open $msg(path)} in] {
  57.     Exmh_Status $in
  58.     return
  59.     }
  60.     set file [Env_Tmp]/postscript.[pid]
  61.     if [catch {open $file w 0600} out] {
  62.     Exmh_Status $out
  63.     }
  64.     Exmh_Status "Postscript in $file"
  65.     while {[gets $in line] >= 0} {
  66.     if [regexp {^%!} $line match] {
  67.         puts $out $match
  68.         puts $out [read $in]
  69.         break
  70.     }
  71.     }
  72.     close $in
  73.     close $out
  74.     # Because $print(cmd) embeds $file, extra levels of eval are required
  75.     if {[catch {eval eval exec $print(pscmd)} logvar]} {
  76.     if [Exwin_Toplevel .printmsg "Print Messages"] {
  77.         Widget_Message .printmsg msg -aspect 1500 -relief raised 
  78.     }
  79.     .printmsg.msg configure -text \
  80. "Messages generated when printing your message:
  81.  
  82. $logvar
  83. "
  84.  
  85.     }
  86. }
  87.  
  88. proc Message_Apply { {body {}} } {
  89.     global exmh msg mhProfile print exwin
  90.     if [catch {open $msg(path)} in] {
  91.     Exmh_Status $in
  92.     return
  93.     }
  94.     if {[string compare $body body] == 0} {
  95.     set file [Env_Tmp]/exmh.body.$msg(id).[pid]
  96.     set what Body
  97.     set print(cleanup) 1
  98.     set print(redisplay) 0
  99.     if [catch {open $file w 0600} out] {
  100.         Exmh_Status $out
  101.         close $in
  102.         return
  103.     }
  104.     while {[gets $in line] >= 0} {
  105.         if {[regexp -- {^ *$} $line] || [regexp -- {^-*$} $line]} {
  106.         puts -nonewline $out [read $in]
  107.         break
  108.         }
  109.     }
  110.     close $out
  111.     } else {
  112.     set file $msg(path)
  113.     set what Message
  114.     set print(cleanup) 0
  115.     set print(redisplay) 1
  116.     }
  117.     close $in
  118.  
  119.     set f [frame $exwin(mtext).cmd -bd 2 -relief ridge]
  120.     message $f.msg1 -text "$what in $file\n\$file gets replaced with that pathname" -aspect 1000
  121.     pack $f.msg1 -side top -fill both -padx 10 -pady 10
  122.  
  123.     set e1 [frame $f.e1 -bd 2 -relief flat]
  124.     label $e1.label -text "UNIX Command: "
  125.     entry $e1.entry -width 20 -textvariable print(unixcmd)
  126.     pack $e1.entry -side right -fill both -expand true
  127.     pack $e1.label -side right
  128.     pack $e1 -side top -fill both -padx 10 -pady 10
  129.  
  130.     set print(cancel) 0
  131.     set b3 [frame $f.but3 -bd 10 -relief flat]
  132.     button $b3.cancel -text "Cancel" -command {Message_ApplyCancel}
  133.     button $b3.ok -text "OK" -command {Message_ApplyOk}
  134.     Widget_BindEntryCmd $e1.entry <Return> {Message_ApplyOk}
  135.     if {$print(cleanup)} {
  136.     checkbutton $b3.nuke -text "Cleanup [Env_Tmp]" -variable print(cleanup)
  137.     } else {
  138.     checkbutton $b3.nuke -text "Redisplay msg" -variable print(redisplay)
  139.     }
  140.     pack $b3.cancel $b3.nuke $b3.ok -side left -padx 3
  141.     pack $b3 -side top
  142.  
  143.     Widget_PlaceDialog $exwin(mtext) $f
  144.     tkwait window $f
  145.  
  146.     if {$print(cancel)} {
  147.     if {$print(cleanup)} {
  148.         File_Delete $file
  149.     }
  150.     Exmh_Focus
  151.     return
  152.     }
  153.  
  154.     # Because $print(cmd) embeds $file, extra levels of eval are required
  155.     set what Output
  156.     if {[catch {eval eval exec $print(unixcmd)} logvar]} {
  157.     set what Errors
  158.     }
  159.     if {[string length $logvar] > 0} {
  160.     if [Exwin_Toplevel .unixmsg "Unix Messages"] {
  161.         Widget_Text .unixmsg 10 
  162.     }
  163.     .unixmsg.t delete 1.0 end
  164.     .unixmsg.t insert 1.0 "$what generated by\n$print(unixcmd)\n\n"
  165.     .unixmsg.t insert end $logvar
  166.     }
  167.     if {$print(redisplay)} {
  168.     Msg_Redisplay $msg(path)
  169.     }
  170.     if {$print(cleanup)} {
  171.     File_Delete $file
  172.     }
  173.     Exmh_Focus
  174. }
  175. proc Message_ApplyCancel {} {
  176.     global print exwin
  177.     set print(cancel) 1
  178.     destroy $exwin(mtext).cmd
  179. }
  180. proc Message_ApplyOk {} {
  181.     global print exwin
  182.     set print(cancel) 0
  183.     destroy $exwin(mtext).cmd
  184. }
  185.